#!/usr/bin/env bash
# 系统管理子菜单（换源/更新/系统信息/cron）

system_menu_show() {
  clear
  echo -e "${YELLOW}【系统管理】${RESET}"
  echo -e "  ${GREEN}1.${RESET} 换源 - 阿里云"
  echo -e "  ${GREEN}2.${RESET} 换源 - 清华大学"
  echo -e "  ${GREEN}3.${RESET} 换源 - 中科大"
  echo -e "  ${GREEN}4.${RESET} 换源 - 华为云"
  echo -e "  ${GREEN}5.${RESET} 换源 - 北外"
  echo -e "  ${GREEN}6.${RESET} 换源 - 上海交大"
  echo -e "  ${GREEN}7.${RESET} 恢复上一次备份源"
  echo -e "  ${GREEN}8.${RESET} 完整更新系统 (update + upgrade + full-upgrade + autoremove)"
  echo -e "  ${GREEN}9.${RESET} 查看系统信息"
  echo -e "  ${GREEN}10.${RESET} 安装并启用 Cron 定时任务"
  echo ""
  echo -e "  ${GREEN}0.${RESET} 返回主菜单"
}

system_menu_loop() {
  while true; do
    system_menu_show
    read -rp "请选择 [0-10]: " a
    case "$a" in
      1)  pick "换源 - 阿里云";            run_or_stub change_mirror_aliyun ;;
      2)  pick "换源 - 清华大学";          run_or_stub change_mirror_tuna ;;
      3)  pick "换源 - 中科大";            run_or_stub change_mirror_ustc ;;
      4)  pick "换源 - 华为云";            run_or_stub change_mirror_huaweicloud ;;
      5)  pick "换源 - 北外";              run_or_stub change_mirror_bfsu ;;
      6)  pick "换源 - 上海交大";          run_or_stub change_mirror_sjtu ;;
      7)  pick "恢复上一次备份源";          run_or_stub restore_sources_backup ;;
      8)  pick "完整更新系统";              run_or_stub system_update ;;
      9)  pick "查看系统信息";              run_or_stub show_system_info ;;
      10) pick "安装并启用 Cron";           run_or_stub install_and_enable_cron ;;
      0)  break ;;
      *)  echo -e "${RED}${BOLD}❌ 无效输入，请重试${RESET}" ;;
    esac
    [[ "$a" != 0 ]] && read -rp "按回车键返回上级..."
  done
}
